package com.ruoyi.detection.controller;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: base-planthopper-detection-master_202130504106_李航
 * @description: 用来前端到后端的Date数据从String自动转换到Date类型
 *
 *              有使用到Date类型的控制层继承该类即可
 *
 * @author: LiHang
 * @create: 2021-09-24 15:59
 **/
@Controller
public class DateController {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }



}
